package com.example.myapplication.designmode.single;

/**
 * 建造(构建)者模式
 */
public class BuilderModel {

    private int height;
    private int width;
    private String color;


    public BuilderModel(Builder builder){
        this.height = builder.height;
        this.width = builder.width;
        this.color = builder.color;
    }

    @Override
    public String toString() {
        return "BuilderModel{" +
                "height=" + height +
                ", width=" + width +
                ", color='" + color + '\'' +
                '}';
    }

    public static final class Builder{
        private int height;
        private int width;
        private String color;

        public BuilderModel Build() {
           return new BuilderModel(this);
        }
        public Builder() {
            this.height = 100;
            this.width = 200;
            this.color = "red";
        }

        public int getHeight() {
            return height;
        }

        public Builder setHeight(int height) {
            this.height = height;
            return this;
        }

        public int getWidth() {
            return width;
        }

        public Builder setWidth(int width) {
            this.width = width;
            return this;
        }

        public String getColor() {
            return color;
        }

        public Builder setColor(String color) {
            this.color = color;
            return this;
        }

        @Override
        public String toString() {
            return "Builder{" +
                    "height=" + height +
                    ", width=" + width +
                    ", color='" + color + '\'' +
                    '}';
        }
    }

}
